package com.piece.admin.model;

import com.piece.core.framework.annotation.translate.DicTranslate;
import com.piece.core.framework.support.model.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@Entity
@NoArgsConstructor
@Table(name = "tb_sys_dept")
@ApiModel(value = "部门表:tb_sys_dept")
public class TbSysDept extends BaseEntity implements Serializable {

    @Id
    @Column(name = "dept_id", length = 11)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @ApiModelProperty(value = "主键")
    private Long deptId;

    @Column(name = "parent_id", length = 11)
    @DicTranslate(target = "parentName", proxy = "tbSysDeptService.convertIdToName")
    @ApiModelProperty(value = "父部门id")
    private Long parentId;

    @Transient
    @ApiModelProperty(value = "父部门名称")
    private String parentName;

    @Column(name = "ancestors", length = 250)
    @ApiModelProperty(value = "祖级列表")
    private String ancestors;

    @Column(name = "dept_name", length = 30)
    @ApiModelProperty(value = "部门名称")
    private String deptName;

    @Column(name = "order_num", length = 4)
    @ApiModelProperty(value = "显示顺序")
    private String orderNum;

    @Column(name = "type", length = 1)
    @ApiModelProperty(value = "类别", notes = "0机构 1部门")
    private String type;

    @Column(name = "leader", length = 30)
    @ApiModelProperty(value = "负责人")
    private String leader;

    @Transient
    @ApiModelProperty(value = "负责人")
    @DicTranslate(source = "leader", proxy = "tbSysUserService.convertIdToName")
    private String leaderName;

    @Column(name = "phone", length = 11)
    @ApiModelProperty(value = "联系电话")
    private String phone;

    @Column(name = "email", length = 50)
    @ApiModelProperty(value = "邮箱")
    private String email;

    @Column(name = "status", length = 1)
    @ApiModelProperty(value = "状态", notes = "0=正常,1=删除,2=停用")
    private String status;

    @Transient
    @ApiModelProperty(value = "状态")
    @DicTranslate(source = "status", dicType = "sys_normal_disable")
    private String statusName;

    @Column(name = "remark", length = 500)
    @ApiModelProperty(value = "备注")
    private String remark;

    @Transient
    @ApiModelProperty(value = "是否有下级部门")
    private boolean hasChildren;

    @Transient
    @ApiModelProperty(value = "下级部门列表")
    private List<TbSysDept> children = new ArrayList<>();
}
